#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<assert.h>

namespace lyz
{
	template<class T>
	class vector
	{

	public:
		typedef T* iterator;
		typedef const T* const_iterator;


		vector()
			:_begin(nullptr)
			, _finish(nullptr)
			, _end_of_storage(nullptr)
		{
		}

		size_t capacity()
		{
			return _end_of_storage - _begin;
		}

		size_t size()
		{
			return _finish - _begin;
		}

		void reserve(size_t n)
		{
			if (n > capacity())
			{
				size_t old = size();
				T* tmp = new T[n];
				if (_begin)
				{
					memcpy(tmp, _begin, old * sizeof(T));
					delete[]_begin;
				}
				_start = tmp;
				_finish = _start + old;
				_end_of_storage = _start + n;
			}
		}

		void push_back(const T& x)
		{
			if (_finish == _end_of_storage)
			{
				int newcapacity = capacity() == 0 ? 4 : capacity() * 2;
				reserve(newcapacity);
			}

			*_finish = x;
			_finish++;
		}


	private:
		_begin;
		_finish;
		_end_of_storage;
	};

}